package com.order.controller;

import com.order.dao.FoodDao;
import com.order.pojo.Food;
import com.order.service.FoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("food")
public class FoodController {
    /*@Autowired
    private FoodDao foodDao;*/
    @Autowired
    private FoodService foodService;
    //添加菜品并且返回主键
    @RequestMapping("/addFood")
    @ResponseBody
    public Integer addFood(Food food)
    {
       // return foodDao.insert(food);
        Integer insert = foodService.insert(food);
        if(insert==1)
            return food.getId();
        else
            return -1;
    }

    @RequestMapping("/findFoods")
    @ResponseBody
    public List<Food> findAll()
    {
        return foodService.findAll();
    }

}
